<? 
	$title="Delete Product"; 
	$pageid="2";
	$accessid="a00";

	require("required/dbconnect.php"); 
	require("required/function.php");
	
	
	checkAccess("allow_product_delete",1);
	
	if(isset($_POST['btnsubmit']))
	{
		$id=$_POST['hidid'];
		$get_info=mysql_query("select * from os_products where id=$id");
		$m=mysql_fetch_array($get_info,MYSQL_ASSOC);
		
		
		
		$get_photo=mysql_query("select id,name from os_productpic where product_id=$id");
		
		if(mysql_num_rows($get_photo)>0)
		{
			while($p=mysql_fetch_array($get_photo,MYSQL_ASSOC))
			{
				$photo_name=$p['name'];
				$file_l = "../productpic/$photo_name";
				$file_s = "../productpic/thumbnails/$photo_name";
				if(file_exists($product_pic))
				{
					unlink($product_pic);
				}
				if(file_exists($product_pic_s))
				{
					unlink($product_pic_s);
				}
				$delete=mysql_query("delete from os_productpic where id=".$p['id']);
			}
		}
		
		mysql_query("delete from os_products where id=$id");
		mysql_query("delete from os_product_inventory where pid=$id");
		header("Location:product_viewall.php");
			
	}
	else
	{
		require("required/header.php");
		$id=$_GET['id'];
		
		$get_product=mysql_query("select * from os_products where id=$id");
		
		if(mysql_num_rows($get_product)==0)
		{
			die("no product found!");
		}
		
		$a=mysql_fetch_array($get_product,MYSQL_ASSOC);
	
	
?>
<table width="100%">
	
	<td align="left" valign="top">
		<table width="100%" cellpadding="2" cellspacing="1"  >
		<tr>
			<td class="title">
				Delete Product
			</td>
		</tr>
		<form action="<?= $_SERVER['PHP_SELF'] ?>" method="post">
		<tr>
			<td>Confirm to delete <?= $a['product_name_chn'] ?> <?= $a['product_name_eng'] ?> ?</td>
		</tr>
		<input type="hidden" value="<?= $id ?>" name="hidid">
		<tr>
			<td><input type="submit" value="Yes" class="button" name="btnsubmit"> <input type="button" value="No" class="button" onClick="history.go(-1)"></td>
		</tr>
		</form>		
		</table>
	</td>
</table>
<? }require("required/footer.php"); ?>

